<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Main controller for showing the index
 */
class Main extends CI_Controller {

    public $data;

    function __construct() {
        parent::__construct();
        // CHECK LOGIN                     << START >>
        $is_logged_in = $this->session->userdata('is_logged_in');
        if (!isset($is_logged_in) || $is_logged_in != TRUE) {
            echo "Unauthorized... Redirecting to login site.";
            redirect('admin/login', 'refresh');
            die();
        }
        // CHECK LOGIN                      << END >>
        // load session data to $data
        $this->data = $this->session->all_userdata();
    }

    function index() {
        redirect('admin/main/control_panel', 'refresh');
    }

    /**
     * Admin főoldal
     */
    function control_panel() {
        $this->data['username'] = $this->session->userdata('username');
        $this->data['title'] = "Vezérlőpult";
        $this->data['current_page'] = "control_panel";

        // a menüt itt gonoszul lehívom returnbe.
        $this->data['menu'] = $this->load->view('admin/menu', $this->data, TRUE);
        
        $this->load->view('admin/header', $this->data);
        $this->load->view('admin/control_panel', $this->data);
        $this->load->view('admin/footer');
    }

    /**
     * Felhasználói beállítások
     */
    function user_settings() {

        $this->data['title'] = "Felhasználói beállítások";
        $this->data['current_page'] = "user_settings";

        // a menüt itt gonoszul lehívom returnbe.
        $this->data['menu'] = $this->load->view('admin/menu', $this->data, TRUE);

        $this->load->view('admin/header', $this->data);
        $this->load->view('admin/user_settings', $this->data);
        $this->load->view('admin/footer');
    }
    
    /**
     * Session megsemmisítő funkció
     */
    function logout() {
        $this->session->sess_destroy();
        redirect('admin/login', 'refresh');
    }

}